package com.ruoyi.web.controller.report;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.BusinessReport;
import com.ruoyi.report.service.IBusinessReportService;
import com.ruoyi.sale.domain.ReceiveRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * description
 *
 * @author h w
 * @version 1.0
 * @date 2023/2/3 20:58
 */
@RestController
@RequestMapping("/business/report")
public class BusinessReportController extends BaseController {

    @Autowired
    private IBusinessReportService businessReportService;

    /**
     * 查询列表
     */
//    @PreAuthorize("@ss.hasPermi('business:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessReport businessReport)
    {
        startPage();
        List<BusinessReport> list = businessReportService.selectBusinessReportList(businessReport);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public List<BusinessReport> listAll(BusinessReport businessReport)
    {
        return businessReportService.selectBusinessReportList(businessReport);
    }

    /**
     * 导出列表
     */
//    @PreAuthorize("@ss.hasPermi('business:report:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessReport businessReport)
    {
        List<BusinessReport> list = businessReportService.selectBusinessReportList(businessReport);
        ExcelUtil<BusinessReport> util = new ExcelUtil<BusinessReport>(BusinessReport.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

}
